﻿<!--
 Peter
 Created by: Peter Development Team
    http://peter.codeplex.com/
 
 GNU General Public License version 2 (GPLv2)
    http://peter.codeplex.com/license
 
 This code is provided on an AS IS basis, with no WARRANTIES,
  CONDITIONS or GUARANTEES of any kind.
-->
<UserControl x:Class="Peter.View.ViewCodeExplorer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:logic="clr-namespace:Peter.Logic"
             xmlns:icons="clr-namespace:Peter.Common.Icons;assembly=Peter.Common"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300"
             d:DataContext="{d:DesignInstance logic:ModelCodeExplorer}">
    <Grid>
        <Grid.Resources>
            <CollectionViewSource x:Key="_Code"
                               Source="{Binding Path=CodeStructure}">
                <CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="ObjectType" />
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource>
        </Grid.Resources>

        <ListBox ItemsSource="{Binding Source={StaticResource _Code}}"
               SelectedItem="{Binding Path=SelectedItem}">
            <ListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Expander Header="{Binding Path=Name, Converter={StaticResource _Pluralizer}}"
                                                  IsExpanded="True">
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListBox.GroupStyle>

            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="IsSelected"
                       Value="{Binding Path=IsSelected}" />
                    <Setter Property="IsEnabled"
                       Value="{Binding Path=IsEnabled}" />
                    <Setter Property="ToolTip"
                       Value="{Binding Path=ToolTip}" />
                </Style>
            </ListBox.ItemContainerStyle>

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="10,0,0,0">
                        <icons:IconDisplay Icon="{Binding Path=Icon}" />
                        <TextBlock Text="{Binding Path=Text}"
                                   Margin="4,0,0,0" />
                        <TextBlock Text=" : "
                                   x:Name="_TxtReturnTypeColon"
                                   Margin="4,0,0,0" />
                        <TextBlock Text="{Binding Path=ReturnType}"
                                   x:Name="_TxtReturnType"
                                   Margin="4,0,0,0"
                                   Foreground="Blue"/>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=ReturnType}"
                                     Value="{x:Null}">
                            <Setter TargetName="_TxtReturnType"
                                    Property="Visibility"
                                    Value="Collapsed"/>
                            <Setter TargetName="_TxtReturnTypeColon"
                                    Property="Visibility"
                                    Value="Collapsed"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=ReturnType}"
                                     Value="">
                            <Setter TargetName="_TxtReturnType"
                                    Property="Visibility"
                                    Value="Collapsed"/>
                            <Setter TargetName="_TxtReturnTypeColon"
                                    Property="Visibility"
                                    Value="Collapsed"/>
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>
